(* Copyright Per Lindgren 2015, see the file "LICENSE" *)
(* for the full license governing this code.           *)

(* FUN-4SURE/Env *)

open Common
open AST
open ST
open List

let lookup env err id = 
  if mem id env then ()  
  else raise (RtfmError("Identifer " ^ st_of_id id ^ " not found in " ^ st_of_id_env env ^ err))

let st_of_t_env env =
  let id_t (id, t) = Id.get_s id ^ " : " ^ st_of_ptype t in
  String.concat ", " (map id_t env)
   
let t_of_id id env =
  try
    assoc id env
  with
  | _ ->  raise 
    (RtfmError("Identifier " ^ st_of_id id ^ " not found in {" ^ st_of_t_env env ^ "}" ))   

let rec filt_opt f l = 
  match l with
  | []     -> []  
  | e :: l -> 
    (
    match f e with 
    | Some id -> id :: filt_opt f l
    | None -> filt_opt f l
    )

let rec evt_of_gu = function EcGuard (_, Some eid, _) -> Some eid | _ -> None 

let gu_of_ecc = function
  | EcGuard (_, eid_opt, _) -> eid_opt
                        
